Yacon.widget.TPanel = function(conText){	
	
	Yacon.apply(this,conText);
	
	if(this.view){
		this.element = this.view;
		this.panel = this.view.panel;
		this.elementID = this.view.id;
		this.elementType = this.view.type;
	}
};

Yacon.widget.TPanel.prototype = {
	
	getHtml: function(){
		
		var html = "";
		
		html += "<div class='panel row-ht-auto col' style='margin-bottom: 0px;' ";
		
		html += " lily-id='"+this.elementID+"' lily-type='"+this.elementType+"' ";
		
		html += " >";
		
		if(this.panel.title){
			html += this.getHeadHtml();
		}
			
		html += this.getBodyHtml();
		
		if(this.panel.bottom){
			html += this.getFootHtml();
		}
		
		html += "</div>";
		
		return html;
		
	},
	
	/* 获取头Html */
	getHeadHtml: function(){
		
		var html = "";
		
		html += "<div class='panel-heading bk-bg-primary row-ht-fix'>";
		
		if(this.panel.isClose){
			html += "<button type='button' class='close panel-close-fix' data-dismiss='modal'>";
			html += "<span aria-hidden='true'>×</span> <span class='sr-only'>Close</span>";
			html += "</button>";
		}
		
		var ico = Yacon.def.window_ico;
		if(this.panel.title.ico){
			ico = this.panel.title.ico;
		}
		
		html += "<h5><span class='"+ico+"'></span>&nbsp;&nbsp;"+this.panel.title.name+"</h5>";
		
		if(this.panel.tmenu){
			
			//高度含BUG
			this.topMenu = new Yacon.widget.TMenu(this.panel.tmenu.menu);
			this.topMenu.parent = this;
			this.topMenu.page = this.page;
			
			if(Yacon.isEmpty(this.panel.topbtn)){
				html += this.topMenu.getTopHtml();
			}else if(this.panel.topbtn == "ico"){
				html += this.topMenu.getTopHtml();
			}else if(this.panel.topbtn == "all"){
				html += this.topMenu.getBottomHtml();
			}else {
				html += this.topMenu.getTopHtml();
			}
			
		}
		
		html += "</div>";
		
		return html;		
	},
	
	/* 获取体HTML信息 */
	getBodyHtml: function(){
		
		var html = "";
		
		html += "<div class='panel-body row-ht-auto col' style='overflow-y:auto;'>";
		
		var content = this.panel.content;
		var contentSize = content.length;
		
		for(var i=0;i<contentSize;i++){
			
			var component = content[i];
			
			if(component.kind == "form"){
				
				var form = new Yacon.widget.TForm({view:component,page:this.page});
				
				form.parent = this;
				this.page.addComponet(form);
		
				html += form.getHtml();
				
			}
			
			else if(component.kind == "tree"){
				
				var tree = new Yacon.component.TTree({view:component,page:this.page});
				
				tree.parent = this;
				
				this.page.addComponet(tree);
				
				html += tree.getHtml();
				
			}
			
			else if(component.kind == "toutframe"){
				
				var frame = new Yacon.widget.TOutFrame({view:component,page:this.page});
				
				frame.parent = this;
				
				this.page.addComponet(frame);
				
				html += frame.getHtml();
				
			}
			
			else if(component.kind == "charts"){
				
				var charts = new Yacon.component.ECharts({view:component,page:this.page});
				charts.parent = this;			
				this.page.addComponet(charts);
				
				html += charts.getHtml();
				
			}
			
			else if(component.kind == "picbox"){
				
				var picbox = new Yacon.widget.TPictureBox({view:component,page:this.page});
				picbox.parent = this;
				this.page.addComponet(picbox);
				
				html += picbox.getHtml();
				
			}
			
		}
		
		html += "</div>";
		
		return html;
		
	},
	
	/* 获取底部Html */
	getFootHtml: function(){
		
		var html = "";
		
		html += "<div class='panel-footer bk-bg-primary row-ht-fix'>";
		
		html += "<div class='pull-right' isWindowControl='true'>";
		
		var buttons = this.panel.bottom.buttons;	
		for(var i=0;i<buttons.length;i++){
			html += new Yacon.widget.TButton(buttons[i]).getBottomHtml();
			html += "&nbsp;&nbsp;";
		}
		
		html += "</div>";
		
		html += "<div class='clearfix'> </div>";
		
		html += "</div>";
		
		return html;
		
	},
	
	addEvents: function(){
		
		Yacon.callBack(this.elementID+"_beforeEvent", [this,this.page]);
		
		var self = this;
		
		var page = this.page;
		var windows = this.page.windows;
		
		var search = this.page.element.search + " div[lily-id='"+this.elementID+"'][lily-type='"+this.elementType+"']";	
		
		$(search+" .panel-footer button[lily-player='button']").unbind("click");
		$(search+" .panel-footer button[lily-player='button']").click(function(){
			
			var button = new Yacon.widget.TButton($(this));
			
			if(windows){
				button.dataSet = windows.dataSet;
			}else{
				button.dataSet = new Yacon.data.DataSet(page);
			}
			
			button.page = page;
			button.component = self;
				
			button.addEvent();
			
		});
		
		if(!Yacon.isEmpty(this.topMenu)){		
			this.topMenu.addTopClick(".panel-heading");
			this.topMenu.addBottomClick(".panel-heading");		
		}
		
		/* 时间控件处理 */
		new Yacon.widget.TDropDate().addEvent();
		
		Yacon.callBack(this.elementID+"_afterEvent", [this,this.page]);
		
	},
	
	layoutBefore: function(){
		
	}
		
};